package cn.jb698.codec.enums;


/**
 * <枚举>,是/否/未知
 * @author LIU
 * @date 2023-02-26 20:46:22
 */
public enum YesNoUnknownEnum {

    /**
     * 是否未知<枚举>: 1是,2否,0未知
     */
	UNKOWN(0,"未知"), 
	YES(1,"是"), 
	NO(2,"否"),  
	;

	private Integer code ;
	private String name ;

	public Integer getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    YesNoUnknownEnum(int code , String name ){
		this.code = code ;
		this.name = name;
	}


	/**
	 * 根据编码获取枚举
	 * @param code
	 * @return
	 */
	public static YesNoUnknownEnum getByCode(Integer code){
		if(code == null ) {
			return null;
		}
		for(YesNoUnknownEnum tmpEnum : values() ){
			if(tmpEnum.getCode().equals(code) ){
				return tmpEnum ;
			}
		}
		return null ;
	}
	
	/**
	 * CODE是否符合
	 * @param code
	 * @return
	 */
	public static boolean isCodeValid(Integer code){
		if(code == null ) {
			return false;
		}
		for(YesNoUnknownEnum tmpEnum : values() ){
			if(tmpEnum.getCode().equals(code) ){
				return true ;
			}
		}
		return false ;
	}
	
}
